<?php
require("../libs/fpdf/fpdf.php");
require("../services/class/listaPlanillasOS.php");
$listaPlanilla = new class_listaPlanillasOS();
$params = array();
$params[0]->cod_planilla_cobro = $_REQUEST["cod_planilla_cobro"]; 
$result = $listaPlanilla->method_getObraSocialTipo1($params,$error);
$data = $result->values;
$extras = $result->extras;

class PDF extends FPDF
{
	public $col = Array(18,55,25,15,40,20,17);
	public $header =array('Fecha','Nombre','Nro Afiliado','Cod. Prac.','Descrip.', 'Cod. Hab.', 'Importe');
	public $importe;
	function Header(){
	    //Logo
	    $this->Cell(1);
	    $this->Image('../resource/membrete.png','','','210');
	    //Arial bold 15
	    $this->SetFont('Arial','B',10);
	    //Title
	   	$this->Ln(10);
	    $this->Cell(110,25,'SRES.'.$this->obra_social,0,0,'L');
	    //Subtitle
	    $this->Ln(10);
	    $this->Cell(110,25,'Detalle de prestaciones correspondientes a '. $this->plan,0,0,'C');
	    //Line break
	    $this->Ln(15);
	    
	//Colors, line width and bold font
    $this->SetFillColor(0,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(180,180,180);
    $this->SetLineWidth(.3);
    $this->SetFont('','B',9);
    //Header
	$this->SetX(10);	
    for($i=0;$i<count($this->header);$i++)
        $this->Cell($this->col[$i],7,$this->header[$i],1,0,'C',true);
    $this->Ln();
    //Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');
	    
   
	}
	function Footer()
	{
	    //Position at 1.5 cm from bottom
	    $this->SetY(-15);
	    //Arial italic 8
	    $this->SetFont('Arial','I',8);
	    //Page number
	    $this->Cell(0,10,'Pag '.$this->PageNo(),0,0,'C');
	}
	
	function Table($header,$data)
	{
		$this->SetX(10);
	    //Color and font restoration
	    $this->SetFillColor(255,255,255);
	    $this->SetTextColor(0);
	    $this->SetFont('');
	    //Data
	    $fill=false;
	    foreach($data as $row)
	    {
	        $this->Cell($this->col[0],6,$row->fecha,1,0,'L',$fill);
	        $this->Cell($this->col[1],6,$row->nombre,1,0,'L',$fill);
	        $this->Cell($this->col[2],6,$row->nro_afiliado,1,0,'L',$fill);
	        $this->Cell($this->col[3],6,$row->codigo_nomenclador,1,0,'L',$fill);
	        $this->Cell($this->col[4],6,substr($row->descripcion,0,23).".",1,0,'L',$fill);
	        $this->Cell($this->col[5],6,$row->codigo_habilitacion,1,0,'L',$fill);
	        $this->Cell($this->col[6],6, number_format($row->importe, 2, ",", "."),1,0,'R',$fill);
	        $this->Ln();
	        $fill=!$fill;
	        $this->importe += $row->importe;
	    }
	}
}

$pdf=new PDF();
//Data loading
$pdf->obra_social = $extras[0]->obra_social;
$pdf->plan = $extras[0]->plan;
$pdf->SetFont('Arial','',7);
$pdf->AddPage();
$pdf->Table($header,$data);
$pdf->SetX(10);
$pdf->Cell(array_sum($pdf->col),0,'','T');
// print totals
$pdf->SetFont('','B','9');
$pdf->Cell(20,6,"  ",'','',R,false);
$pdf->ln();
$pdf->setX(160);
$pdf->Cell(20,6,"Total:  ",'','',R,false);
$pdf->setX(160);
$pdf->Cell(40,6,number_format($pdf->importe, 2, ",", "."),'','',R,false);
$pdf->setX(10);
$pdf->ln();
$pdf->SetFont('','BI','9');
$pdf->Cell(200,6,"TOTAL:   " . owFunciones::NumberToString($pdf->importe),'','',L,false);
$pdf->Output();
?>